package B.w.OOday04;
/** 测试类 */
public class Test {
    public static void main(String[] args) {
        //引用所指向的对象，就是该类型
        //引用所指向的对象，实现了该接口的链接
        //建议：在强转之前先通过instanceof来判断引用的对象是否是该类型
        //注意：instanceof返回boolean结果，它为true的条件就是强转成功地调解
       /* Animal o=new Dog("小黑",2,"黑");
        Dog d=(Dog) o;//引用o的对象，就是Doo类型-----此处强转o成Dog型
        Swim s=(Swim) o;//引用o的对象，实现了Swim接口
        //Fish f=(Fish)o;// 运行时会发生ClassCastException类型转换

        System.out.println(o instanceof Dog);//true
        System.out.println(o instanceof  Swim);//true
       // System.out.println(o instanceof Fish);//false*/
       /* Master master=new Master();
        Dog dog=new Dog("小黑",2,"黑");
        Fish fish=new Fish("小金",2,"金");
        Chick chick=new Chick("小花",1,"花");
        master.feed(dog);//在传参的同时，系统自动做了向上造型
        master.feed(fish);
        master.feed(chick);*/

       /* Animal []animals=new Animal[5];
        animals[0]=new Dog("小黑",2,"黑");
        animals[1]=new Dog("小白",1,"白");
        animals[2]=new Fish("小金",2,"金");
        animals[3]=new Fish("大金",4,"白");
        animals[4]=new Chick("小花",1,"花");
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
        }

        if(animals[i]instanceof Dog){
            Dog dog=(Dog) animals[i];
            dog.lookHome();
            dog.swim();
        }
        if (animals[i]instanceof Fish){
            Fish fish=(Fish) animals[i];
            fish.swim();
        }
        if (animals[i]instanceof Chick){
            Chick chick=(Chick) animals[i];
            chick.layEggs();
        }
        if(animals[i]instanceof Swim){
            Swim s=(Swim) animals[i];
            s.swim();
        }*/
    }
}

























        /*Dog dog = new Dog("小黑",2,"黑");
        System.out.println(dog.name);
       // dog = null;
      // System.out.println(dog.name);


        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑",2,"黑");
        dogs[1] = new Dog("小白",1,"白");
        dogs[2] = new Dog("小灰",3,"灰");
        System.out.println(dogs[0].name);
        dogs[1].age = 4;
        dogs[2].swim();
        for(int i=0;i<dogs.length;i++){
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }
        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("小花",1,"花");
        chicks[1] = new Chick("大花",3,"白");
        for(int i=0;i<chicks.length;i++){
            System.out.println(chicks[i].name);
            chicks[i].eat();
        }
        Fish[] fish = new Fish[4];
        fish[0] = new Fish("小金",2,"金");
        fish[1] = new Fish("大金",4,"白");
        fish[2] = new Fish("小绿",1,"绿");
        fish[3] = new Fish("大绿",3,"白");
        for(int i=0;i<fish.length;i++){
            System.out.println(fish[i].name);
            fish[i].eat();
        }
*/




















